package com.example;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;

@Component
public class ProxyHttpReqeust {
    @Value("${proxy.address}")
    String proxyAddress;

    @Autowired
    RestTemplate restTemplate;

    //可以自定义注解，通过反射检测注解的方法，调用代理类
    //这里只是做个简单的demo
    public  Object get(HttpServletRequest request){
        return restTemplate.getForObject(
                proxyAddress+request.getRequestURI().replace("/api",""),Object.class);
    }
}
